package company.tx1;

import java.util.*;

public class Tx3A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // n个数
        int n = sc.nextInt();
        // 前k大 前k小
        int k = sc.nextInt();
        sc.nextLine();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.nextLine();
            map.put(s, map.getOrDefault(s, 0) + 1);
        }
        TreeMap<Integer, TreeSet<String>> dict = new TreeMap<>();
        for (Map.Entry<String, Integer> e : map.entrySet()) {
            TreeSet<String> treeSet = dict.getOrDefault(e.getValue(), new TreeSet<>());
            treeSet.add(e.getKey());
            dict.put(e.getValue(), treeSet);
        }
        NavigableMap<Integer, TreeSet<String>> dict1 = dict.descendingMap();
        ArrayList<String> list = new ArrayList<>();
        helper(dict1, k, list);
        helper(dict, k, list);
        for (String s : list) {
            System.out.println(s);
        }
    }

    private static void helper(Map<Integer, TreeSet<String>> dict, int num, ArrayList<String> list) {
        Loop:
        for (Map.Entry<Integer, TreeSet<String>> e : dict.entrySet()) {
            Integer count = e.getKey();
            TreeSet<String> value = e.getValue();
            for (String s : value) {
                if (num > 1) {
                    list.add(s + " " + count);
                    num -= 1;
                } else {
                    list.add(s + " " + count);
                    break Loop;
                }
            }
        }
    }
}

